package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Pay;
import com.ruoyi.system.service.IPayService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 参合缴费登记Controller
 *
 * @author moweiyu
 * @date 2021-05-21
 */
@Controller
@RequestMapping("/system/pay")
public class PayController extends BaseController
{
    private String prefix = "system/pay";

    @Autowired
    private IPayService payService;

    @RequiresPermissions("system:pay:view")
    @GetMapping()
    public String pay()
    {
        return prefix + "/pay";
    }

    /**
     * 查询参合缴费登记列表
     */
    @RequiresPermissions("system:pay:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Pay pay)
    {
        startPage();
        List<Pay> list = payService.selectPayList(pay);
        return getDataTable(list);
    }

    /**
     * 导出参合缴费登记列表
     */
    @RequiresPermissions("system:pay:export")
    @Log(title = "参合缴费登记", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Pay pay)
    {
        List<Pay> list = payService.selectPayList(pay);
        ExcelUtil<Pay> util = new ExcelUtil<Pay>(Pay.class);
        return util.exportExcel(list, "参合缴费登记数据");
    }

    /**
     * 新增参合缴费登记
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存参合缴费登记
     */
    @RequiresPermissions("system:pay:add")
    @Log(title = "参合缴费登记", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Pay pay)
    {
        return toAjax(payService.insertPay(pay));
    }

    /**
     * 修改参合缴费登记
     */
    @GetMapping("/edit/{payId}")
    public String edit(@PathVariable("payId") Long payId, ModelMap mmap)
    {
        Pay pay = payService.selectPayById(payId);
        mmap.put("pay", pay);
        return prefix + "/edit";
    }

    /**
     * 修改保存参合缴费登记
     */
    @RequiresPermissions("system:pay:edit")
    @Log(title = "参合缴费登记", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Pay pay)
    {
        return toAjax(payService.updatePay(pay));
    }

    /**
     * 删除参合缴费登记
     */
    @RequiresPermissions("system:pay:remove")
    @Log(title = "参合缴费登记", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(payService.deletePayByIds(ids));
    }
}
